<!doctype html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>擅长</title>
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
        <link href="../../../css/mui.min.css" rel="stylesheet" />
        <style>
            .tip {
                padding: 10px 15px;
            }
        </style>
    </head>
    <body>
        <header class="mui-navbar-inner mui-bar mui-bar-nav">
            <button type="button" class="mui-left mui-action-back mui-btn mui-btn-link mui-btn-nav mui-pull-left">
                <span class="mui-icon mui-icon-left-nav"></span>
            </button>
            <h1 class="mui-center mui-title">擅长</h1>
            <button type="button" class="mui-btn mui-btn-success mui-pull-right" id="save">保存</button>
        </header>
        <div class="mui-content">
            <form class="mui-input-group" name="frmMain">
                <div class="mui-input-row">
                    <input type="text" placeholder="擅长一" name="goodAt0" maxlength="10">
                </div>
                <div class="mui-input-row">
                    <input type="text" placeholder="擅长二" name="goodAt1" maxlength="10">
                </div>
                <div class="mui-input-row">
                    <input type="text" placeholder="擅长三" name="goodAt2" maxlength="10">
                </div>
            </form>
            <h5 class="tip">可以录入三项擅长，每项字数不超过10个</h5>
        </div>
        <script src="../../../js/mui.min.js"></script>
        <script src="../../../js/http.js"></script>
        <script src="../../../js/userInfo.js"></script>
        <script type="text/javascript">
            var $ = mui, doc = document;
            $.init({
                beforeback: function() {
                    //获得列表界面的webview
                    var info = plus.webview.getWebviewById('info');
                    //触发列表界面的自定义事件（refresh）,从而进行数据刷新
                    mui.fire(info, 'refreshInfo');
                    //返回true，继续页面关闭逻辑
                    return true;
                }
            });
            $.plusReady(function(params) {
                getGoodAt();
            });

            // 保存事件
            doc.getElementById('save').addEventListener('tap', function() {
                var goodAtValue = '', ary = [];
                for (var i = 0; i < 3; i++) {
                    goodAtValue = doc.frmMain['goodAt' + i].value.trim();
                    goodAtValue && ary.push(goodAtValue);
                };
                if (!ary.length) {
                    $.toast("请录入擅长");
                } else {
                    save(ary.join('#'));
                }
            });

            // 初始化擅长信息
            function getGoodAt() {
                for (var i = 0; i < 3; i++) {
                    doc.frmMain['goodAt' + i].value = userInfo.regdoctor.goodAtList[i] || '';
                };
            }
            // 调用保存接口
            function save(goodAt) {
                // 请求 地址 参数 类型
                plus.nativeUI.showWaiting('保存中...');
                var opt = {
                    UserID: userInfo.regdoctor.userID,
                    GoodAt: goodAt
                };
                myHttp('/inquiry/update', opt, 'post', function (res) {
                    plus.nativeUI.closeWaiting();
                    if (res.success) {
                        $.toast("保存成功");
                        // 更新用户信息缓存
                        userInfo.regdoctor.goodAt = goodAt;
                        userInfo.regdoctor.goodAtList = goodAt.split('#');
                        plus.storage.setItem('userInfo', JSON.stringify(userInfo));
                        //登录成功
                        $.back();
                    } else {
                        $.toast("保存失败");
                    }
                });
            }

        </script>
    </body>
</html>